/****************************************************
 * Description: Entity for 用户基本信息
 * Copyright:   Copyright (c) 2014
 * Company:     beiwaionline
 * @author      bfsu
 * @version     1.0
 * @see
	HISTORY
    *  2014-01-10 bfsu Create File
**************************************************/

package com.bfsuol.bfsuolframework.security.dao;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bfsuol.bfsuolframework.core.entity.Entity;
import com.bfsuol.bfsuolframework.core.entity.EntitySupport;
import lombok.Data;
import lombok.experimental.Accessors;
import org.codehaus.jackson.annotate.JsonIgnore;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;

@Data
@Accessors(chain = true)
@TableName("t_sec_base_user")
public class BaseUser extends EntitySupport implements Entity {

    private static final long serialVersionUID = 1L;

    public BaseUser(){}
    public BaseUser(Long id){
        this.id = id;
    }

    @TableId(type = IdType.AUTO,value = "base_user_id")
    private Long id;
    @TableField(value = "login_name")
    private String loginName;//用户名
    @TableField(value = "password")
    private String password;//密码
    @TableField(value = "user_name")
    private String userName;//中文名
    @TableField(value = "pinyin_name_zh")
    private String pinyinNameZh;//中文名拼音
    @TableField(value = "user_name_en")
    private String userNameEn;//英文名
    @TableField(value = "nickname")
    private String nickname;//昵称
    @TableField(value = "gender")
    private Integer gender;//性别
    @TableField(value = "birthday")
    private Date birthday;//生日
    @TableField(value = "home_phone")
    private String homePhone;//家庭电话
    @TableField(value = "mobile")
    private String mobile;//手机
    @TableField(value = "msn")
    private String msn;//MSN
    @TableField(value = "qq")
    private String qq;//QQ
    @TableField(value = "address")
    private String address;//地址
    @TableField(value = "postcode")
    private String postcode;//邮编
    @TableField(value = "email")
    private String email;//email
    @TableField(value = "register_date")
    private Date registerDate;//注册时间
    @TableField(value = "online_time")
    private Long onlineTime;//在线时长
    @TableField(value = "login_count")
    private Long loginCount;//登录次数
    @TableField(value = "last_login_time")
    private Date lastLoginTime;//最后登录时间
    @TableField(value = "last_login_ip")
    private String lastLoginIp;//最后登录IP
    @TableField(value = "status")
    private Integer status;//状态
    @TableField(value = "user_type")
    private Integer userType;//用户类型
    @TableField(value = "img_url")
    private String imgUrl;//照片URL
    @TableField(value = "create_user_id")
    private Long createUserId;//创建人id
    @TableField(value = "create_user_name")
    private String createUserName;//创建人姓名
    @TableField(value = "create_time")
    private Date createTime;//创建时间
    @TableField(value = "update_user_id")
    private Long updateUserId;//更新人id
    @TableField(value = "update_user_name")
    private String updateUserName;//更新人姓名
    @TableField(value = "update_time")
    private Date updateTime;//更新时间

    @TableField(exist = false)
    private transient Collection<Role> roles;//角色
    @TableField(exist = false)
    private transient Collection<Group> groups;//用户组

    /**
     */
    public void addRole(Role role) {
        if(this.roles == null){
            this.roles = new HashSet<Role>();
        }
        this.roles.add(role);
    }

    /**
     */
    public void removeRole(Role role) {
        if(this.roles == null){
            return;
        }
        this.roles.remove(role);
    }

    /**
     */
    public void addGroup(Group group) {
        if(this.groups == null){
            this.groups = new HashSet<Group>();
        }
        this.groups.add(group);
    }

    /**
     */
    public void removeGroup(Group group) {
        if(this.groups == null){
            return;
        }
        this.groups.remove(group);
    }

    public boolean isNew() {
        return getId() == null || getId().longValue()<=0;
    }
}

